#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
#define sort stable_sort
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf,ubuf[1<<23],*u=ubuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
	TP x=0;
	int f=0;
	char ch=getchar();
	while(ch<48||ch>57) f|=ch=='-',ch=getchar();
	while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return num=f?-x:x;
}
template<typename ...Args> inline void read(Args &...args)
{
	(read(args),...);
}
template<typename TP> inline void write(TP x)
{
	(x<0)?(putchar('-'),x=-x):0;
	(x>9)?(write(x/10),0):0;
	putchar((x%10)^48);
}
template<typename TP> inline void writeln(TP x)
{
	write<TP>(x);
	puts("");
}
int q,opt,l,r,rr;
multiset<int> ls,rs;
multiset<int> dist;
map<pair<int,int>,pair<int,int>> mp;
inline void force()
{
	vector<pair<int,int>> v;
	while(q--)
	{
		while(!isalpha(opt=getchar()));
		read(l,r),--r;
		if(opt=='A') v.emplace_back(l,r);
		else
		{
			int o=0;
			rep(i,0,(int)v.size()-1) if(v[i].first==l&&v[i].second==r) {o=i;break;}
			v.erase(v.begin()+o);
		}
		if(v.size()==1u) writeln(v[0].second-v[0].first+1);
		else
		{
			int aa=1e18,res=1e18;
			rep(i,0,(int)v.size()-1) rep(j,i+1,(int)v.size()-1)
			{
				int now=max(v[i].second,v[j].second)-min(v[i].first,v[j].first)+1;
				int overlap=1e18;
				if((v[i].first<=v[j].first&&v[j].second<=v[i].second)||(v[j].first<=v[i].first&&v[i].second<=v[j].second))overlap=min(v[i].second-v[i].first+1,v[j].second-v[j].first+1);
				else if(v[i].second<v[j].first||v[j].second<v[i].first)overlap=0;
				else overlap=max(v[i].second-v[j].first,v[j].second-v[i].first);
				if(overlap<aa)aa=overlap,res=now;
				if(overlap==aa&&now<res) res=now;
			}
			writeln(res);
		}
	}
	exit(0);
}
signed main()
{
	freopen("stone.in","r",stdin);
	freopen("stone.out","w",stdout);
	read(q);
	if(q<=500) force();
	while(q--)
	{
		while(!isalpha(opt=getchar()));
		read(l,r),--r;
		if(opt=='A')
		{
			ls.emplace(l);
			auto it=rs.upper_bound(l);
			int res1=1e18,res2=1e18;
			if(it!=rs.end()) res1=*it-l+1;
			ls.erase(ls.find(l));
			rs.emplace(r);
			it=ls.lower_bound(r);
			if(it!=ls.begin()) res2=r-*prev(it)+1;
			ls.emplace(l);
			dist.emplace(res1),dist.emplace(res2);
			mp[{l,r}]={res1,res2};
		}
		else
		{
			rs.erase(rs.find(r));
			auto it=rs.upper_bound(l);
			int res1=1e18,res2=1e18;
			if(it!=rs.end()) res1=*it-l+1;
			ls.erase(ls.find(l));
			rs.emplace(r);
			it=ls.lower_bound(r);
			if(it!=ls.begin()) res2=r-*prev(it)+1;
			rs.erase(rs.find(r));
			dist.erase(res1),dist.erase(res2);
			dist.erase(mp[{l,r}].first),dist.erase(mp[{l,r}].second);
		}
		if(ls.size()==1) writeln(*rs.begin()-*ls.begin()+1);
		else writeln(*dist.begin());
	}
	return 0;
}
